<template>
	<view>
		<about v-if="PageCur=='about'" ref="about"></about>
		<release v-if="PageCur=='release'"></release>
		<activity v-if="PageCur=='activity'" ref="activity"></activity>
		<view class="cu-bar tabbar bg-white shadow foot">
			<view class="action" @click="NavChange" data-cur="activity">
				<view class='cuIcon-cu-image'>
					<image :src="'/static/tabbar/basics' + [PageCur=='activity'?'_cur':''] + '.png'"></image>
				</view>
				<view :class="PageCur=='activity'?'text-green':'text-gray'">发现</view>
			</view>
			<view class="action" @click="NavChange" data-cur="release">
				<view class='cuIcon-cu-image'>
					<image :src="'/static/tabbar/plugin' + [PageCur == 'release'?'_cur':''] + '.png'"></image>
				</view>
				<view :class="PageCur=='release'?'text-green':'text-gray'">发布</view>
			</view>
			<view class="action" @click="NavChange" data-cur="about">
				<view class='cuIcon-cu-image'>
					<image :src="'/static/tabbar/about' + [PageCur == 'about'?'_cur':''] + '.png'"></image>
				</view>
				<view :class="PageCur=='about'?'text-green':'text-gray'">我的</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		SHARE_CODE_PAGE_IMG,
		MY_SHARE_CODE,
		SYS_INFO,
		SHARE_TITLE,
		FRONT_BASE_URL
	} from '@/common/util.js'
	import {loadSysInfo} from '@/common/sys-info.js'
	export default {
		data() {
		return {
				PageCur: 'activity',
				sysInfo: {},
				frontBaseUrl: FRONT_BASE_URL,
				shareCode: null
			}
		},
		onLoad(options) {
			// 首页的分享
			if (options.shareCode) {
				uni.setStorageSync(SHARE_CODE, options.shareCode)
			}
			// 小程序分享码
			if (options.scene) {
				uni.setStorageSync(SHARE_CODE, options.scene)
			}
			loadSysInfo(this)
		},
		onShow() {
			this.shareCode = uni.getStorageSync(MY_SHARE_CODE);
			if (!this.shareCode) {
				uni.hideShareMenu()
			} else {
				uni.showShareMenu()
			}
			if (this.PageCur == 'activity') {
				this.$refs.activity.initLoad()
			} else if (this.PageCur == 'about') {
				this.$refs.about.initLoad()
			}
		},
		onShareAppMessage(res) {
			let shareImgUrl = SHARE_CODE_PAGE_IMG;
			if (this.sysInfo.shareImg) {
				shareImgUrl = this.frontBaseUrl + this.sysInfo.shareImg
			}
			let shareTitle = SHARE_TITLE 
			if (this.sysInfo.shareTitle) {
				shareTitle = this.sysInfo.shareTitle
			}
			return  {
				title: shareTitle,
				path: '/pages/index/index?shareCode=' + this.shareCode,
				imageUrl: shareImgUrl
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			if (this.PageCur == 'activity') {
				this.$refs.activity.initLoad()
			} else if (this.PageCur == 'about') {
				this.$refs.about.initLoad()
			}
			setTimeout(()=>{
				uni.stopPullDownRefresh();
			},1000)
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			}
		}
	}
</script>

<style>

</style>
